<template>
  <view class="main">
    <uni-forms>
      <uni-forms-item label="用户名">
        <uni-easyinput v-model="user.username" />
      </uni-forms-item>
      <uni-forms-item label="密码">
        <uni-easyinput type="password" v-model="user.password" />
      </uni-forms-item>
      <uni-forms-item>
        <button @click="reg" type="primary" size="default">注册</button>
        <button type="warn" size="default">重填</button>
        <button @click="login" type="default" size="default">返回登录</button>
      </uni-forms-item>
    </uni-forms>
  </view>
</template>

<script setup>
  import {
    ref
  } from 'vue'
  import {
    api
  } from '@/js/api.js'

  const user = ref({
    "username": "",
    "password": ""
  })

  const login = () => {
    uni.switchTab({
      url: '/pages/my/my'
    })
  }

  const reg = () => {
    api.post('/user/reg', user.value, (data) => {
      uni.showModal({
        content: data.message,
        showCancel: false,
        title: '注册结果'
      })
    })
  }
</script>

<style scoped>
  .main {
    padding: 1rem;
  }

  button {
    margin: 0.5rem;
  }
</style>